package com.ustb.service.impl;

import com.ustb.entity.Result;
import com.ustb.mapper.UserMapper;
import com.ustb.pojo.User;
import com.ustb.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    /**
     * 用户登录
     * @param user
     * @return
     */
    @Override
    public Result login(User user) {
        User user4Db = userMapper.login(user);
        if(user4Db!=null){
            return new Result(true,"登录成功",user4Db);
        }else{
            return new Result(false,"登录失败",null);
        }
    }

    /**
     * 用户注册
     * @param user
     * @return
     */
    @Override
    public Result reg(User user) {
        userMapper.reg(user);
        return new Result(true,"注册成功",user);
    }

    /**
     * 根据ID获取用户信息
     * @param id
     * @return
     */
    @Override
    public Result findUserById(Integer id) {
        User user = userMapper.findUserById(id);
        return new Result(true,"根据ID获取用于详细信息",user);
    }
}
